#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	int ma = 0;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += max(0, arr[i] - arr[i - 1]);
	}
	cout << ans << endl;
	return 0;
}